<?php

namespace app\model;

use think\Model;

class AdvertModel  extends Model {

    protected $name = 'advert';

    protected $pk = 'id'; // 明确声明主键字段

    // 自动时间戳
    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';


    // 跳转类型获取器
    public function getJumpTypeAttr($value)
    {
        $status = [0 => '无', 1 => '端内', 2 => '端外'];
        return $status[$value];
    }

    // 搜索器
    public function searchIsShowAttr($query, $value)
    {
        $value !== '' && $query->where('is_show', $value);
    }

    public function searchAdIdAttr($query, $value)
    {
        $value && $query->where('ad_id', $value);
    }
}